//----BEGIN LICENSE----//
/*****************************************************************\
** prevalentLite - sqlite3 persistence object library 
**
** Copyright (C) 2008 Philip R. Schuchardt
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************/
//----END LICENSE----//
#ifndef pl_FACTORY_ELEMENT_H
#define pl_FACTORY_ELEMENT_H

/*---------------------------------------------------------
        This class statically registers elements to the class factory.
        Want's the factory starts up it traversase list of plFactoryElements
        until it gets to the end.  This list is statically defined.

        This class shouldn't be used directly
-------------------------------------------------------------*/

#include "plObject.h"

class plFactoryElement {

public:
    //Constructor for the factory element
    plFactoryElement(const char* className, plObject* (*newFunctionPtr) ());

    //Gets the name
    const char* GetClassName() {
        return ClassName;
    }

    ///////////////////////////////////////////////////////////////////////
    // Purpose: Creates a new object of T
    //////////////////////////////////////////////////////////////////
    template <class T>
            static plObject* ObjectFactoryFunction() {
        plObject* object = new T();
        return object;
    } //end ObjectFactoryFunction()
    /////////////////////////////////////////////////////////////////

    //The name of the class
    const char* ClassName;

    //The function pointer to create a new object
    plObject* (*NewFunctionPtr) ();

    //Head and next of the linked list
    static plFactoryElement* Head;
    plFactoryElement* Next;
}; //end plFactoryElement

#endif 

